package com.ruoyi.web.controller.process;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.process.domain.WorkPacking;
import com.ruoyi.process.service.IWorkPackingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 装箱管理Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/process/packing")
public class WorkPackingController extends BaseController
{
    @Autowired
    private IWorkPackingService workPackingService;

    /**
     * 查询装箱管理列表
     */
    @PreAuthorize("@ss.hasPermi('process:packing:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkPacking workPacking)
    {
        startPage();
        List<WorkPacking> list = workPackingService.selectWorkPackingList(workPacking);
        return getDataTable(list);
    }

    /**
     * 导出装箱管理列表
     */
    @PreAuthorize("@ss.hasPermi('process:packing:export')")
    @Log(title = "装箱管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkPacking workPacking)
    {
        List<WorkPacking> list = workPackingService.selectWorkPackingList(workPacking);
        ExcelUtil<WorkPacking> util = new ExcelUtil<WorkPacking>(WorkPacking.class);
        return util.exportExcel(list, "装箱管理数据");
    }

    /**
     * 获取装箱管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('process:packing:query')")
    @GetMapping(value = "/{workPackingId}")
    public AjaxResult getInfo(@PathVariable("workPackingId") Long workPackingId)
    {
        return AjaxResult.success(workPackingService.selectWorkPackingById(workPackingId));
    }

    /**
     * 新增装箱管理
     */
    @PreAuthorize("@ss.hasPermi('process:packing:add')")
    @Log(title = "装箱管理", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type= InjectType.Insert)
    public AjaxResult add(@RequestBody WorkPacking workPacking)
    {
        return toAjax(workPackingService.insertWorkPacking(workPacking));
    }

    /**
     * 修改装箱管理
     */
    @PreAuthorize("@ss.hasPermi('process:packing:edit')")
    @Log(title = "装箱管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type= InjectType.Update)
    public AjaxResult edit(@RequestBody WorkPacking workPacking)
    {
        return toAjax(workPackingService.updateWorkPacking(workPacking));
    }

    /**
     * 删除装箱管理
     */
    @PreAuthorize("@ss.hasPermi('process:packing:remove')")
    @Log(title = "装箱管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workPackingIds}")
    public AjaxResult remove(@PathVariable Long[] workPackingIds)
    {
        return toAjax(workPackingService.deleteWorkPackingByIds(workPackingIds));
    }
}
